package com.zut.base.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zut.base.common.entry.ResultCode;
import com.zut.base.common.entry.ResultVO;
import com.zut.base.entity.Systemconfig;
import com.zut.base.service.ISystemconfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyl
 * @since 2021-04-07
 */
@RestController
@RequestMapping("/imp/systemconfig")
public class SystemconfigController {
    @Autowired
    private ISystemconfigService systemconfigServiceImpl;

    @GetMapping("/change")
    public Object changeRegister() {
        QueryWrapper<Systemconfig> systemconfigQueryWrapper = new QueryWrapper<>();
        Systemconfig systemconfig = systemconfigServiceImpl.getOne(systemconfigQueryWrapper);
        if(systemconfig==null) return new ResultVO<>(ResultCode.FAILED, "操作失败");
        systemconfigQueryWrapper.eq("id", systemconfig.getId());
        systemconfig.setAllowregister(Integer.parseInt(systemconfig.getAllowregister())==1?"0":"1");
        boolean update = systemconfigServiceImpl.update(systemconfig, systemconfigQueryWrapper);
        if(!update) return new ResultVO<>(ResultCode.FAILED, "操作失败");
        Map<String, Object> map = new HashMap<>();
        map.put("status", "OK");
        map.put("allowregister", systemconfig.getAllowregister());
        return new ResultVO<>(200, "操作成功", map);
    }

    @GetMapping("/check")
    public Object check() {
        QueryWrapper<Systemconfig> systemconfigQueryWrapper = new QueryWrapper<>();
        Systemconfig systemconfig = systemconfigServiceImpl.getOne(systemconfigQueryWrapper);
        if(systemconfig==null) return new ResultVO<>(ResultCode.FAILED, "查看状态失败");
        Map<String, Object> map = new HashMap<>();
        map.put("status", "OK");
        map.put("allowregister", systemconfig.getAllowregister());
        return new ResultVO<>(200, "查看状态成功", map);
    }
}
